import React from 'react';
import Icon from './Icon';
import FileButton from './FileButton';
import { noop } from '../utils';

/**
 * 预览按钮
 * @param {any} props 
 */
export default function FileButtonPreview(props) {
    const {
        listType,
        file = {},
        ifShowPreview,
        onPreview = noop,
        children,
        ...otherProps
    } = props;

    const { state = '' } = file;

    if (!ifShowPreview || state === 'error') {
        return null;
    }
    
    return (
        <FileButton
            listType={listType}
            file={file}
            name="preview"
            onClick={e => {
                onPreview(file, e);
            }}
            {...otherProps}
        >
            {children || <Icon type="eye" />}
        </FileButton>
    );
}
